﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.DomainLayer;

using System.Collections.ObjectModel;
namespace HA.ModFlow.Controls
{
   public class PCGHBCollecion:PCBase 
    {
     public   PCGHBCollecion(GHBCollection ghb)
       {
           this._GHBCollection = ghb ;

           this._periodStep = new List<int>();

           for (int i = 0; i < ghb.NPeriods; i++)
           {

               this._periodStep.Add(i + 1);

           }


           this._lstUsePrecious = new List<bool>();

           this._lstUsePrecious.AddRange(ghb.IsUsePrecious);




           this._GHBs = new ObservableCollection<PCGHB>();

           foreach (GeneralHead  item in ghb .InnerList)
           {
               PCGHB pc = new PCGHB((GeneralHead) item.Clone());

               this._GHBs.Add(pc);

           }

       }

       private GHBCollection _GHBCollection;


       bool _isShowId = true;

       public bool IsShowId
       {
           get { return _isShowId; }
           set { _isShowId = value; }
       }




       List<bool> _lstUsePrecious;

       public bool UsePreciousEnabled
       {
           get
           {
               if (this._currentPeriod == 0)
               {
                   return false;
               }
               else
               {
                   return true;
               }
           }

       }

       public bool UsePrecious
       {
           get
           {
               if (_lstUsePrecious.Count == 0)
                   return false;
               return this._lstUsePrecious[this._currentPeriod];


           }
           set
           {



               this._lstUsePrecious[this._currentPeriod] = value;
               this._GHBCollection.IsUsePrecious[this._currentPeriod] = value;
               this.OnPropertyChanged("UsePrecious");

           }
       }

       //具体的index值

       int _currentPeriod = 0;

       public int CurrentPeriod
       {
           get { return _currentPeriod; }
           set
           {


               _currentPeriod = value;

               this.UsePrecious = this._GHBCollection.IsUsePrecious[_currentPeriod];

               foreach (PCGHB item in this._GHBs)
               {
                   item.CurrentIndex = this._currentPeriod;

               }

               this.OnPropertyChanged("UsePreciousEnabled");

               this.OnPropertyChanged("UsePrecious");


           }
       }

       List<int> _periodStep;

       public List<int> PeriodStep
       {
           get { return _periodStep; }

       }

       ObservableCollection<PCGHB> _GHBs;

       public ObservableCollection<PCGHB> GHBs
       {
           get { return _GHBs; }
           set { _GHBs = value; }
       }


       public void CreateNew()
       {
           GeneralHead general = new GeneralHead(1, 1, 1, this._GHBCollection.Nrows, this._GHBCollection.Ncols, this._GHBCollection.Nlayers, this._periodStep.Count);

           PCGHB pcNew = new PCGHB(general);

           this.GHBs.Add(pcNew);
       }


       public void ConfirmData()
       {

           List<GeneralHead> GeneralHeads = new List<GeneralHead>();

           foreach (PCGHB  item in this._GHBs)
           {
               GeneralHeads.Add(item.GeneralHead);

           }

           this._GHBCollection.ResetGHB(GeneralHeads);

           this._GHBCollection.ResetIsUsePrecious(this._lstUsePrecious);





       }
       /// <summary>
       /// 检查层行列的正确定性
       /// </summary>
       /// <param name="row"></param>
       /// <param name="col"></param>
       /// <param name="layer"></param>
       /// <param name="index"></param>
       /// <param name="isIndexId"></param>
       /// <returns></returns>
       public bool CheckInputIJKorIndex(int row, int col, int layer, int index, bool isIndexId)
       {
           foreach (PCGHB item in this._GHBs)
           {
               if (!isIndexId)
               {
                   if (item.I <= 0 || item.I > row)//行
                   {
                       System.Windows.MessageBox.Show("不存在第 " + item.I + " 行，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                       return false;
                   }
                   if (item.J <= 0 || item.J > col)
                   {
                       System.Windows.MessageBox.Show("不存在第 " + item.J + " 列，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                       return false;
                   }
                   if (item.K <= 0 || item.K > layer)
                   {
                       System.Windows.MessageBox.Show("不存在第 " + item.K + " 层，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                       return false;
                   }
               }
               else
               {
                   if (item.Index <= 0 || item.Index > index)
                   {
                       System.Windows.MessageBox.Show("不存在 " + item.Index + " 单元格ID，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                       return false;
                   }

               }
           }

           return true;
       }

     

    }
   public class PCGHB : PCBase
   {


       public PCGHB(GeneralHead  ghb)
       {
           this._GeneralHead = ghb;

       }

       GeneralHead _GeneralHead;

       public GeneralHead GeneralHead
       {
           get { return _GeneralHead; }          
       }

      



       int _currentIndex = 0;

       public int CurrentIndex
       {
           get { return _currentIndex; }
           set
           {


               _currentIndex = value;


               this.OnPropertyChanged("Head");
               this.OnPropertyChanged("Conductance");
               //this.OnPropertyChanged("Elevation");



           }
       }




       public int Index
       {
           get
           {
               return this._GeneralHead.Index;


           }
           set
           {


               this._GeneralHead.Index = value;

               this.OnPropertyChanged("I");
               this.OnPropertyChanged("J");
               this.OnPropertyChanged("K");

           }
       }



       public int I
       {
           get { return this._GeneralHead.I; }
           set
           {
               this._GeneralHead.I = value;

               this.OnPropertyChanged("Index");


           }

       }


       public int J
       {
           get { return this._GeneralHead.J; }
           set
           {
               this._GeneralHead.J = value;

               this.OnPropertyChanged("Index");
           }
       }


       public int K
       {
           get { return this._GeneralHead.K; }
           set
           {
               this._GeneralHead.K = value;


               this.OnPropertyChanged("Index");

           }
       }


       public double Head
       {
           get { return this._GeneralHead.Head [this._currentIndex]; }

           set { this._GeneralHead.Head[this._currentIndex] = value; }
       }


       public double Conductance
       {
           get { return this._GeneralHead.Conductance[this._currentIndex]; }

           set { this._GeneralHead.Conductance[this._currentIndex] = value; }

       }

       //public double Elevation
       //{

       //    get { return this._GeneralHead.Elevation[this._currentIndex]; }

       //    set { this._GeneralHead.Elevation[this._currentIndex] = value; }


       //}

   }
}